package com.health.viewscontrols;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.health.R;
import com.health.db.DbManager;
import com.health.db.FDbManager;
import com.health.httpbean.model.BpModel;
import com.health.httpbean.model.PoModel;
import com.health.httpbean.model.UeModel;
import com.health.model.FeiXinBingFollowupNew;
import com.health.model.FengShiBingFollowupNew;
import com.health.model.LeiFengShiFollowupNew;
import com.health.model.LvYueFuWuBean;
import com.health.model.ManZuFeiFollowupNew;
import com.health.tablebean.BD_DD_AREA;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.BD_ORGANIZE_EMPLOYEE;
import com.health.tablebean.BD_ORGANIZE_INSTITUTION;
import com.health.tablebean.HD_PERSONAL_HEALTH_PHOTO;
import com.health.tablebean.JTYSCustomerDoctorCont;
import com.health.tablebean.SBCL_DATA;
import com.health.tools.FileUtils;
import com.health.tools.GlobalConts;
import com.health.tools.SPUtil;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.XXPermissions;
import com.sinocare.multicriteriasdk.MulticriteriaSDKManager;
import com.sinocare.multicriteriasdk.auth.AuthStatusListener;
import com.sinocare.multicriteriasdk.utils.AuthStatus;
import com.yanzhenjie.permission.Action;
import com.yanzhenjie.permission.AndPermission;

import android.Manifest;
import android.annotation.TargetApi;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

/**
 * 程序启动界面
 */

public class SplashActivity extends NovaActivity {
    private static final String TAG = "SplashActivity";
    private TextView tv_version;

    @Override
    protected void onDestroy() {
        super.onDestroy();
        try {
            // 退出App
            MulticriteriaSDKManager.finishAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 三诺sdk鉴权
     */
    private void authenticationSDK() {

//        MulticriteriaSDKManager.initAndAuthentication(getApplication(), new AuthStatusListener() {
//            @Override
//            public void onAuthStatus(AuthStatus authStatus) {
//                Log.e(TAG, "三诺sdk鉴权结果: " + authStatus.toString());
//            }
//        });

        try {
            // 三诺sdk初始化
            MulticriteriaSDKManager.init(getApplication());
            MulticriteriaSDKManager.authentication(new AuthStatusListener() {
                @Override
                public void onAuthStatus(AuthStatus authStatus) {
                    Log.e(TAG, "三诺sdk鉴权结果: " + authStatus.toString());
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        // 隐藏标题栏
        setContentView(R.layout.splash_ac);

        if (!this.isTaskRoot()) {//判断Activity是不是任务空间的源Activity，"非"也就是说是被系统重新实例化出来
            Intent mainIntent = getIntent();
            String action = mainIntent.getAction();
            if (mainIntent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)) {
                finish();
                return;//finish之后改Activity活动会继续执行后面的二代马，你可以logCat验证，加return避免抛Exception
            }
        }

        findViews();
        setListeners();

        // 方法1 Android获得屏幕的宽和高
        WindowManager windowManager = getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        @SuppressWarnings("deprecation")
        int screenWidth = display.getWidth();
        @SuppressWarnings("deprecation")
        int screenHeight = display.getHeight();
        Log.e(TAG, "" + screenWidth + "*" + screenHeight);
        SPUtil.saveInt(this,SPUtil.SP_NAME,"screenWidth",screenWidth);
        SPUtil.saveInt(this,SPUtil.SP_NAME,"screenHeight",screenHeight);

        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        float width = dm.widthPixels * dm.density;
        float height = dm.heightPixels * dm.density;
        Log.w(TAG, "-----" + width + "*" + height);
//        if (Build.VERSION.SDK_INT >= 23) {
//            AndPermission.with(this).permission(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CAMERA).onGranted(new Action() {
//                @Override
//                public void onAction(List<String> permissions) {
//                    initApplicationData();
//                    Handler x = new Handler();
//                    x.postDelayed(new StartHandler(), 300);
//                }
//            }).onDenied(new Action() {
//                @Override
//                public void onAction(List<String> permissions) {
//
//                    Dialog dialog = new AlertDialog.Builder(SplashActivity.this).setTitle("重要提示！").setMessage("你已经拒绝了存储权限或蓝牙权限，请去设置界面开启权限，否则将影响使用！").setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            openSettingDetail();
//                            //关闭app
//                            android.os.Process.killProcess(android.os.Process.myPid());
//                        }
//                    }).show();
//
//                }
//            }).start();
//        } else {
//            initApplicationData();
//            Handler x = new Handler();
//            x.postDelayed(new StartHandler(), 300);
//        }

//        initApplicationData();
//        Handler x = new Handler();
//        x.postDelayed(new StartHandler(), 300);
//        requestPermission();

        FileUtils.isPathExist();
        FileUtils.isPathExist();
        FileUtils.getVideoList();
        initApplicationData();
        Handler x = new Handler();
        x.postDelayed(new StartHandler(), 300);

        authenticationSDK();

        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("网络类型：").append(NetworkUtils.getNetworkType() + "").append("\n");
        stringBuffer.append("手机系统：").append(Build.VERSION.RELEASE).append("\n");
        stringBuffer.append("手机型号：").append(Build.MODEL + "(" + Build.BRAND + ")").append("\n");
        stringBuffer.append("CPU ABI: ").append(Build.CPU_ABI).append("\n");

        Log.e(TAG, "onCreate: " + stringBuffer.toString() );
    }

    private void requestPermission2() {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
//            XXPermissions.with(this)
//                    // 申请单个权限
//                    .permission(
//                            Manifest.permission.BLUETOOTH_SCAN,
//                            Manifest.permission.BLUETOOTH_CONNECT
//                    )
//                    .request(new OnPermissionCallback() {
//
//                        @Override
//                        public void onGranted(@NonNull List<String> permissions, boolean allGranted) {
//                            jumpNextActivity();
//                            Log.e(TAG, "onGranted: " );
//                        }
//
//                        @Override
//                        public void onDenied(@NonNull List<String> permissions, boolean doNotAskAgain) {
//                            jumpNextActivity();
//                            Log.e(TAG, "onDenied: " );
//                        }
//                    });
//        }

    }

    private void requestPermission() {
        AndPermission.with(this)
                .permission(
                        Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.ACCESS_COARSE_LOCATION,
                        Manifest.permission.ACCESS_FINE_LOCATION,
                        Manifest.permission.BLUETOOTH,
                        Manifest.permission.CAMERA
                )
                .onGranted(new Action() {
                    @TargetApi(Build.VERSION_CODES.M)
                    @Override
                    public void onAction(List<String> permissions) {
                        //自定义事件
                        FileUtils.isPathExist();
                        FileUtils.isPathExist();
                        FileUtils.getVideoList();
                        initApplicationData();
                        Handler x = new Handler();
                        x.postDelayed(new StartHandler(), 300);
                    }
                })
                .onDenied(new Action() {
                    @Override
                    public void onAction(@NonNull List<String> permissions) {
                        requestPermission1();
                    }
                })
                .start();
    }

    private void requestPermission1() {
        AndPermission.with(this)
                .permission(
                        Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.ACCESS_COARSE_LOCATION,
                        Manifest.permission.ACCESS_FINE_LOCATION,
                        Manifest.permission.BLUETOOTH,
                        Manifest.permission.CAMERA
                )
                .onGranted(new Action() {
                    @TargetApi(Build.VERSION_CODES.M)
                    @Override
                    public void onAction(List<String> permissions) {
                        //自定义事件
                        FileUtils.isPathExist();
                        FileUtils.isPathExist();
                        FileUtils.getVideoList();
                        initApplicationData();
                        Handler x = new Handler();
                        x.postDelayed(new StartHandler(), 300);
                    }
                })
                .onDenied(new Action() {
                    @Override
                    public void onAction(@NonNull List<String> permissions) {
                        finish();
                    }
                })
                .start();
    }


    /**
     * 初始化数据
     */
    public void initApplicationData() {
        NovaApplication.fdbmanger = FDbManager.getInstance(getApplicationContext());
        NovaApplication.dbManger = DbManager.getInstance(getApplicationContext());
        initCSDB();
        insertAndUpdateData2BD_DDINFO();
    }

    /**
     * 数据库添加和修改字字典值    （门诊DM04-15_1  家庭DM04-15_2   电话DM04-15_3） DM04-04_2修改为家庭访视
     */
    private void insertAndUpdateData2BD_DDINFO() {
        List<BD_DD_INFO> infos = NovaApplication.fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
                "PARENTID = 'DM04-15'");
        if (infos != null && infos.size() > 0) {

        } else {
            BD_DD_INFO bd_dd_info1 = new BD_DD_INFO();
            bd_dd_info1.setDATAINFO("门诊");
            bd_dd_info1.setDATANUM("1");
            bd_dd_info1.setID("DM04-15_1");
            bd_dd_info1.setPARENTID("DM04-15");
            bd_dd_info1.setSORT("1");
            bd_dd_info1.setNBPHSC("Y");
            bd_dd_info1.setPrintNum("1");
            NovaApplication.fdbmanger.saveInInfoDB(bd_dd_info1);

            BD_DD_INFO bd_dd_info2 = new BD_DD_INFO();
            bd_dd_info2.setDATAINFO("家庭");
            bd_dd_info2.setDATANUM("2");
            bd_dd_info2.setID("DM04-15_2");
            bd_dd_info2.setPARENTID("DM04-15");
            bd_dd_info2.setSORT("2");
            bd_dd_info2.setNBPHSC("Y");
            bd_dd_info2.setPrintNum("2");
            NovaApplication.fdbmanger.saveInInfoDB(bd_dd_info2);

            BD_DD_INFO bd_dd_info3 = new BD_DD_INFO();
            bd_dd_info3.setDATAINFO("电话");
            bd_dd_info3.setDATANUM("3");
            bd_dd_info3.setID("DM04-15_3");
            bd_dd_info3.setPARENTID("DM04-15");
            bd_dd_info3.setSORT("3");
            bd_dd_info3.setNBPHSC("Y");
            bd_dd_info3.setPrintNum("3");
            NovaApplication.fdbmanger.saveInInfoDB(bd_dd_info3);

        }
        List<BD_DD_INFO> bd_dd_infos = NovaApplication.fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
                "ID = 'DM04-04_2'");
        if (bd_dd_infos != null && bd_dd_infos.size() > 0) {
            BD_DD_INFO bd_dd_info = bd_dd_infos.get(0);
            if ("家庭".equals(bd_dd_info.getDATAINFO())) {
                bd_dd_info.setDATAINFO("家庭访视");
                NovaApplication.fdbmanger.updataInInfoDB(bd_dd_info, "ID = 'DM04-04_2'");
            }
        }
        NovaApplication.dbManger.addColumnByBySQL("CD_CHD_FOLLOWUP", "IS_UPDATE");
        /*查询单独居室字典值（DM01-102_1:有，DM01-102_2:无）*/
        List<BD_DD_INFO> info = NovaApplication.fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
                "PARENTID = 'DM01-102'");
        if (info != null && info.size() > 0) {

        } else {
            BD_DD_INFO bd_dd_info1 = new BD_DD_INFO();
            bd_dd_info1.setDATAINFO("无");
            bd_dd_info1.setDATANUM("1");
            bd_dd_info1.setID("DM01-102_2");
            bd_dd_info1.setPARENTID("DM01-102");
            bd_dd_info1.setSORT("1");
            bd_dd_info1.setNBPHSC("Y");
            bd_dd_info1.setPrintNum("1");
            NovaApplication.fdbmanger.saveInInfoDB(bd_dd_info1);

            BD_DD_INFO bd_dd_info = new BD_DD_INFO();
            bd_dd_info.setDATAINFO("有");
            bd_dd_info.setDATANUM("2");
            bd_dd_info.setID("DM01-102_1");
            bd_dd_info.setPARENTID("DM01-102");
            bd_dd_info.setSORT("2");
            bd_dd_info.setNBPHSC("Y");
            bd_dd_info.setPrintNum("2");
            NovaApplication.fdbmanger.saveInInfoDB(bd_dd_info);
        }

        /*添加户主关系 DM01-06_0_2 */
        List<BD_DD_INFO> info_hz = NovaApplication.fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
                "ID = 'DM01-06_0_2'");
        if (info_hz != null && info_hz.size() > 0) {

        } else {
            BD_DD_INFO bd_dd_info1 = new BD_DD_INFO();
            bd_dd_info1.setDATAINFO("户主");
            bd_dd_info1.setDATANUM("100");
            bd_dd_info1.setID("DM01-06_0_2");
            bd_dd_info1.setPARENTID("DM01-06");
            bd_dd_info1.setSORT("1");
            bd_dd_info1.setNBPHSC("Y");
            bd_dd_info1.setPrintNum("1");
            NovaApplication.fdbmanger.saveInInfoDB(bd_dd_info1);

        }

    }

    /**
     * 打开设置界面
     */
    public void openSettingDetail() {
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (Build.VERSION.SDK_INT >= 9) {
            intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
            intent.setData(Uri.fromParts("package", getPackageName(), null));
        } else if (Build.VERSION.SDK_INT <= 8) {
            intent.setAction(Intent.ACTION_VIEW);
            intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
            intent.putExtra("com.android.settings.ApplicationPkgName", getPackageName());
        }
        startActivity(intent);
    }

    /**
     * 初始化数据库数据
     */
    private void initCSDB() {
        SBCL_DATA sb = new SBCL_DATA();// 设备测量
        NovaApplication.fdbmanger.save(sb);
        NovaApplication.dbManger.addColumnByBySQL("SBCL_DATA","IS_UPDATE_JKXZ");
        HD_PERSONAL_HEALTH_PHOTO photo = new HD_PERSONAL_HEALTH_PHOTO();// 照片
        NovaApplication.fdbmanger.save(photo);
        JTYSCustomerDoctorCont jtys_khqyb = new JTYSCustomerDoctorCont();// 家庭签约医生表
        NovaApplication.fdbmanger.save(jtys_khqyb);
        FeiXinBingFollowupNew feiXinBingFollowup=new FeiXinBingFollowupNew();//肺心病随访
        NovaApplication.fdbmanger.save(feiXinBingFollowup);
        LeiFengShiFollowupNew leiFengShiFollowup=new LeiFengShiFollowupNew();//类风湿
        NovaApplication.fdbmanger.save(leiFengShiFollowup);
        ManZuFeiFollowupNew manZuFeiFollowup=new ManZuFeiFollowupNew();//慢阻肺
        NovaApplication.fdbmanger.save(manZuFeiFollowup);
        FengShiBingFollowupNew fengShiBingFollowup=new FengShiBingFollowupNew();//风湿病
        NovaApplication.fdbmanger.save(fengShiBingFollowup);




        LvYueFuWuBean lvyue=new LvYueFuWuBean();//添加履约信息表
        NovaApplication.fdbmanger.save(lvyue);
        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","personalId");
        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","is_Update");
        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","signatory");
        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","createOrg");
        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","creater");
        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","createdate");

        //判断用户信息表是否有 签约相关字典
        NovaApplication.dbManger.addColumnByBySQL("ARCHIVE_BASEINFO","QYINFOID");
        NovaApplication.dbManger.addColumnByBySQL("ARCHIVE_BASEINFO","RELATIONID");
        NovaApplication.dbManger.addColumnByBySQL("ARCHIVE_BASEINFO","ZHUYUANHAO");

        //家庭医生客户签约表 新增 签约类型
        NovaApplication.dbManger.addColumnByBySQL("JTYS_KHQYB","signtype");

        //个人基本信息添加字段
        NovaApplication.dbManger.addColumnByBySQL("ARCHIVE_BASEINFO", "ISMATERIALS");
        NovaApplication.dbManger.addColumnByBySQL("ARCHIVE_BASEINFO", "ISPROVERTY");
        //高血压随访添加字段
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "TOSALT");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "HEALTH_ASSESS");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "ISREFERRAL");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "IS_UPDATE_NEW");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "res11");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "res12");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "res13");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "res14");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "res15");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "res16");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "res17");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "res18");

        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug11");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug12");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug13");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug14");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug21");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug22");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug23");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug24");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug31");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug32");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug33");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug34");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug41");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug42");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug43");
        NovaApplication.dbManger.addColumnByBySQL("CD_HYPERTENSIONFOLLOWUP", "drug44");

        //糖尿病随访添加字段
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "HEALTH_ASSESS");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "ISREFERRAL");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "IS_UPDATE_NEW");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "res11");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "res12");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "res13");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "res14");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "res15");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "res16");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "res17");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "res18");

        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug11");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug12");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug13");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug14");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug21");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug22");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug23");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug24");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug31");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug32");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug33");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug34");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug41");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug42");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug43");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "drug44");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "INSULINTYPE2");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "INSULINTYPE3");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "INSULINUSAGE2");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "INSULINUSAGE3");
        NovaApplication.dbManger.addColumnByBySQL("CD_DIABETESFOLLOWUP", "subCheck");

        NovaApplication.dbManger.addColumnByBySQL("CD_DRUGCONDITION", "PARENTID");

//        // 新平台档案表增加是否上传字段
        NovaApplication.dbManger.addColumnByBySQL("ARCHIVE_BASEINFO","IS_UPDATE_NEW");
        // 创建新的体检数据表 对接新平台使用
        NovaApplication.dbManger.createSBCL_DATA_NEWTable();

//        DeviceShowSaveData.saveTiwen("36.5");
//        PwBean pwBean = new PwBean();
//        pwBean.setHdl(12.2);
//        pwBean.setLdl(2.2);
//        pwBean.setTc(4.22);
//        pwBean.setTg(3.22);
//        DeviceShowSaveData.saveXueZhi(GsonUtils.toJson(pwBean));
//        DeviceShowSaveData.saveXuetang(4.2 + "");
//
//        PoModel poModel = new PoModel();
//        poModel.setBloodOxygenSaturation(98 + "");
//        poModel.setHeartRate(65+ "");
//        DeviceShowSaveData.saveXueyang(GsonUtils.toJson(poModel));
//
//        BpModel bpModel = new BpModel();
//        bpModel.setHighpressure(122 + "");
//        bpModel.setLowvoltage(88 + "");
//        bpModel.setPulse(66 + "");
//        DeviceShowSaveData.saveXueya(GsonUtils.toJson(bpModel));
//
//        DeviceShowSaveData.saveTizhong(76 + "");
//
//        UeModel ueModel = new UeModel();
//        ueModel.setUro("1.1");
//        ueModel.setBld("1.2");
//        ueModel.setBil("1.3");
//        ueModel.setKet("1.4");
//        ueModel.setGlu("1.5");
//        ueModel.setPro("1.6");
//        ueModel.setPh("1.7");
//        ueModel.setNit("1.8");
//        ueModel.setLeu("1.9");
//        ueModel.setSg("2.0");
//        ueModel.setVc("2.1");
//        DeviceShowSaveData.saveUE(GsonUtils.toJson(ueModel));

    }


    @Override
    public void findViews() {
        tv_version = (TextView) findViewById(R.id.tv_version);
        String versionName = GlobalConts.getVerName(SplashActivity.this);
        if (!TextUtils.isEmpty(versionName)) {
            tv_version.setText("V  " + versionName);
        } else {
            tv_version.setText("");
        }

    }

    @Override
    public void setListeners() {

    }

    class StartHandler implements Runnable {

        @Override
        public void run() {

//            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
//                requestPermission2();
//            } else {
//                jumpNextActivity();
//            }

            jumpNextActivity();
        }

    }

    private void jumpNextActivity() {
        Intent intent = null;

        if (TextUtils.isEmpty(NovaApplication.getImei()) || TextUtils.isEmpty(NovaApplication.getXzqhNo())
                || SPUtil.getIsShiYong(SplashActivity.this)) {

            intent = new Intent(getApplication(), RegisterActivity.class);
        } else {
            List<BD_DD_AREA> areas = NovaApplication.fdbmanger.findAllByWhere(BD_DD_AREA.class,
                    "GBCODE like'" + NovaApplication.getXzqhNo() + "%'");
            List<BD_ORGANIZE_INSTITUTION> institutions = NovaApplication.fdbmanger
                    .findAllByWhere(BD_ORGANIZE_INSTITUTION.class, "GBCODE like'" + NovaApplication.getXzqhNo() + "%'");

            List<BD_ORGANIZE_EMPLOYEE> employees = NovaApplication.fdbmanger.findAll(BD_ORGANIZE_EMPLOYEE.class,
                    "GBCODE ='" + NovaApplication.getXzqhNo() + "'");
            if (areas.size() == 0 || institutions.size() == 0 || employees.size() == 0) {
                intent = new Intent(getApplication(), HomeDataDownloadActivity.class);
            } else {
                intent = new Intent(getApplication(), ConfigActivity.class);
            }
        }
        if (intent != null) {
            startActivity(intent);
            SplashActivity.this.finish();
        }
    }

}
